

/**
	AUTHOR		: VEERU
	DATE		: JULY 15th 2004
	DESCRIPTION	: THIS PROCEDURE IS USED TO SAVE OR UPDATE THE RELATIONSHIP BETWEEN VENDOR AND SHIPPER.
*/


CREATE  PROC SP_SAVE_VENDOR_SHIPPER_RELATIONSHIP

@VENDOR_ID INT,
@SHIPPER_ID INT

AS
BEGIN

	DECLARE @STATUS_ID INT
	SELECT @STATUS_ID = RELATIONSHIPSTATUS_ID FROM CUSTOMER_RELATIONSHIP_STATUS WHERE NAME = 'ACTIVE'

	IF( ( SELECT COUNT(*) FROM VENDOR_SHIPPER_RELATIONSHIP WHERE VENDOR_ID = @VENDOR_ID AND SHIPPER_ID = @SHIPPER_ID ) = 0 )
	BEGIN
		INSERT INTO VENDOR_SHIPPER_RELATIONSHIP( VENDOR_ID, SHIPPER_ID, RELATIONSHIPSTATUS_ID ) VALUES ( @VENDOR_ID, @SHIPPER_ID, @STATUS_ID )
	END
	ELSE
	BEGIN
		UPDATE VENDOR_SHIPPER_RELATIONSHIP SET RELATIONSHIPSTATUS_ID = @STATUS_ID WHERE VENDOR_ID = @VENDOR_ID AND SHIPPER_ID = @SHIPPER_ID
	END		
END
